import * as THREE from "three";
import axios from "axios";
export const SixExp = {
	methods:{
        async sixExp(){
            this.loading = true
            this.$parent.btnIsDis = true;

            this.getMapData("worldMap") ;
            await   this.loadCountryNumber(6);
            var picArr = [
                {imgUrl:"img/relatedPhoto/Six/Croatia1.jpg",imgDesc:"阿尔巴尼亚和克罗地亚峰会后加入扩大议定书的签署。"},
                {imgUrl:"img/relatedPhoto/Six/Croatia2.jpg",imgDesc:"从左到右: Lulzim Basha (阿尔巴尼亚外交部长)与北约秘书长jJaap de Hoop Scheffer和Gordan Jandrokovic(克罗地亚外交部长)。"},
                {imgUrl:"img/relatedPhoto/Six/Croatia3.jpg",imgDesc:"阿尔巴尼亚和克罗地亚加入北约的仪式-在荣誉法院举行的升旗仪式，阿尔巴尼亚总理萨利-贝里沙和克罗地亚总理伊沃·萨纳德出席SHAPE国际乐队演奏，而SHAPE仪仗队进入仪式位置。"}
            ]
            this.changePicTexture(picArr);

            var newCameraPos,newTargetPos;
            var flagAnimation = [];
            var fontAnimation,knifeAnimation;
            var Group  = new THREE.Group();
            Group.name = "Jb"
            var resource = new THREE.Group();

            // 旗帜数据
            let flagData = [{labelName:"俄罗斯",flagTexturePath:"img/flag/Russia.png",modelName:"Russia"}]
            this.scene.add(Group)

            // 加载资源

            // 刀模型
            var knifeModel = this.gltfLoadModel("model/public/ani_knife/scene.gltf");
            await knifeModel.then((res)=>{
               res.scene.scale.set(0.2,0.2,0.2) ;
               let knife1 = res.scene.clone() ;
               let knife2 = res.scene.clone() ;
               knifeAnimation = res.animations[0] ;
               knife1.name  = "knife1" ;
               knife2.name  = "knife2" ;
               resource.add(knife1) ;
               resource.add(knife2) ;
            })


            // 旗帜模型
            let russiaLabel 	   = this.get3dLabel("俄罗斯",false) ;
            var flagRussiaModel = this.gltfLoadModel("model/public/flaggltf/scene.gltf");
            var flagRussiaTexture = this.changeTexture("img/flag/Russia.png") ;
            await flagRussiaModel.then((res)=>{
                let flag = res.scene.clone();
                flagAnimation = res.animations[0];
                flag.name = "Russia";
                flag.scale.set(4, 4, 4)
                flag.children[0].children[1].material.map = flagRussiaTexture;
                flag.children[0].children[1].material.map.needsUpdate = true;
                flag.add(russiaLabel)
                resource.add(flag)
            })

            let AlbaniaLabel 	   = this.get3dLabel("阿尔巴尼亚",false) ;
            var flagAlbaniaModel = this.gltfLoadModel("model/public/flaggltf/scene.gltf");
            var flagAlbaniaTexture = this.changeTexture("img/flag/Albania.png") ;
            await flagAlbaniaModel.then((res)=>{
                let flag = res.scene.clone();
                flagAnimation = res.animations[0];
                flag.name = "Albania";
                flag.scale.set(4, 4, 4)
                flag.children[0].children[1].material.map = flagAlbaniaTexture;
                flag.children[0].children[1].material.map.needsUpdate = true;
                flag.add(AlbaniaLabel)
                resource.add(flag)
            })

            let CroatiaLabel 	   = this.get3dLabel("克罗地亚",false) ;
            var flagCroatiaModel = this.gltfLoadModel("model/public/flaggltf/scene.gltf");
            var flagCroatiaTexture = this.changeTexture("img/flag/Croatia.png") ;
            await flagCroatiaModel.then((res)=>{
                let flag = res.scene.clone();
                flag.name = "Croatia";
                flag.scale.set(4, 4, 4)
                // 更换材质
                flag.children[0].children[1].material.map = flagCroatiaTexture;
                flag.children[0].children[1].material.map.needsUpdate = true;
                flag.add(CroatiaLabel)
                resource.add(flag)
            })


            var sixExpFont = this.gltfLoadModel("model/date/6-20090401/scene.gltf")
            await sixExpFont.then((res) => {
                let font  =  res.scene ;
                font.scale.set(10, 10, 10) ;
                fontAnimation = res.animations[0] ;
                font.name="20090401"
                resource.add(font)
            })

            this.loading = false

        ///////////////////////////////////////////////////////
            this.sixthPromptText() ;
            this.$refs.Lines.src = "music/lines/sixthexp/6-1.mp3" ;
            this.$refs.Lines.play();



            newCameraPos = {
                x:-7.500238142346362,
                y:34.4003258732726,
                z:87.32369947494728
            }
            newTargetPos = {
                x:27.796248066698908,
                y:0,
                z:-15.418243122098104
            }

            this.animateCamera(this.camera.position, this.controls.target, newCameraPos, newTargetPos, 3000)

            setTimeout(()=>{
                let font = resource.getObjectByName("20090401");
                font.position.set(27.796248066698908,20,-20.418243122098104)
                this.onceActionPlay(fontAnimation,font)
                Group.add(font)
            },1500)


            setTimeout(()=>{
                let flag = resource.getObjectByName("Croatia");
                flag.position.set(27.796248066698908,9,-15.418243122098104);
                this.onceActionPlay(flagAnimation,flag)
                Group.add(flag)
            },3000)

            setTimeout(()=>{
                let flag = resource.getObjectByName("Albania");
                flag.position.set(30.763099670410156,9,-5.809340476989745);
                this.onceActionPlay(flagAnimation,flag)
                Group.add(flag)
            },3500)


            // 后半段动画
            setTimeout(()=>{
                this.$refs.Lines.src = "music/lines/sixthexp/6-2.mp3" ;
                this.$refs.Lines.play();

                 newCameraPos = {
                    x:78.37966206420904,
                    y:60.730252577716584,
                    z:68.843369252841
                }
                 newTargetPos = {
                    x:50.87795709633231,
                    y:4,
                    z:-22.3261086577627
                }

                this.animateCamera(this.camera.position,this.controls.target,newCameraPos,newTargetPos,2000)
            },11000)

            setTimeout(()=>{
                let ruFlag = resource.getObjectByName("Russia");
                ruFlag.position.set(56.747633596820606,9,-35.34143761530109)
                Group.add(ruFlag)
                this.onceActionPlay(flagAnimation,ruFlag)
                this.colorMap("Russia",this.myColor.wtoArea)
            },13500)

            setTimeout(()=>{
                this.colorMap("Ukraine",this.myColor.focusArea)
            },15100)

            setTimeout(()=>{
                this.colorMap("Belarus",this.myColor.focusArea)
            },16000)

            setTimeout(()=>{
                this.colorMap("Moldova",this.myColor.focusArea)
            },17100)

            setTimeout(()=>{
                var knife1= resource.getObjectByName("knife1")
                var knife2= resource.getObjectByName("knife2")
                knife1.position.set(45.029943172514095,5,-23.152252027078532)
                knife1.rotateY(Math.PI * 1.5)
                knife2.rotateY(-Math.PI * 1.5)
                knife2.position.set(47.029943172514095,5,-23.52252027078532)
                Group.add(knife1) ;
                Group.add(knife2) ;

                this.onceActionPlay(knifeAnimation,knife1) ;
                this.onceActionPlay(knifeAnimation,knife2) ;
            },18000)

        }
    }
}